<template>
  <div>
    <el-table
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="分类编号" sortable width="180">
      </el-table-column>
      <el-table-column prop="catename" label="分类名称" sortable width="180">
      </el-table-column>
      <el-table-column prop="img" label="图片"> 
        <template slot-scope="scoped">
          <div>
            <img :src="$pre+scoped.row.img" alt="">
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="状态"> 
        <template slot-scope="scoped">
          <div>
            <el-button type="success" v-if="scoped.row.status==1">启用</el-button>
             <el-button type="info" v-else>禁用</el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column  label="操作">
        <template slot-scope="scoped">
          <div>
            <el-button type="success" @click="update(scoped.row.id)">编辑</el-button>
            <v-del @del="del(scoped.row.id)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { catedelete } from "../../../request/api.js";
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../utils/alert.js";
export default {
  data() {
    return {
     
    };
  },

  methods: {
    ...mapActions({
      catelist: "cate/asyncChangeList",
    }),
    //删除
    del(id){
catedelete({id:id}).then(res=>{
  if(res.data.code==200){
    successAlert(res.data.msg)
    this.catelist()
  }else{
     warningAlert(res.data.msg)
  }
})
    },
    //编辑
    update(id){
      this.$emit('update',id);
      this.catelist()
    }
  },
  computed: {
    ...mapGetters({
      list: "cate/list",
    }),
  },

  mounted() {
    this.catelist();
  },
};
</script>

<style  scoped>
img{
  width: 100px;
  height: 100px;
}
</style>